package com.yunxun.coinmessage.controller;

import com.yunxun.coinmessage.entity.ClassifiedPacket;
import com.yunxun.coinmessage.entity.MesSource;
import com.yunxun.coinmessage.entity.TypeDict;
import com.yunxun.coinmessage.service.ClassifiedPacketService;
import com.yunxun.coinmessage.service.MesSourceService;
import com.yunxun.coinmessage.service.TypeDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class TypeDictController {
    @Autowired
    TypeDictService typeDictService;
    @Autowired
    ClassifiedPacketService classifiedPacketService;
    @Autowired
    MesSourceService mesSourceService;
    @RequestMapping(value = "/typeDict")
    public String findAll(Model model){
       List<TypeDict> typeDicts= typeDictService.findAll();
       List<ClassifiedPacket> classifiedPackets=classifiedPacketService.findAll();
        model.addAttribute("typeDicts",typeDicts);
        model.addAttribute("classifiedPackets",classifiedPackets);
       return "mesSource-add";
    }

    @RequestMapping("/editMesSourceOntTypeDict")
    public String editMesSource(Integer sid, Model model){
        List<TypeDict> typeDicts= typeDictService.findAll();
        List<ClassifiedPacket> classifiedPackets=classifiedPacketService.findAll();
        MesSource mesSource= mesSourceService.queryById(sid);

        model.addAttribute("typeDicts",typeDicts);
        model.addAttribute("classifiedPackets",classifiedPackets);
        model.addAttribute("mesSource",mesSource);
        return "mesSource-edit";
    }

}
